var g_role = null;
var Role = cc.Sprite.extend({
    _HP : 10,
    _effect : null,
    ///////////////////////////////////////////////////////////
    ctor : function(filename){
        this._super(filename);
        g_role = this;
    },
    onEnter:function () {
        this._super();
    },
    onExit : function(){
        this._super();
    },
    hurt : function(hp){
        cc.log("role hurt,hp: "+(this._HP-1) );
        this.hurtEffect();
        if( --this._HP<=0 ){
            // game over
            cc.log("game over");
        }
        var filename = AudioResource("hurt0.mp3");
        cc.audioEngine.playEffect(filename);
    },
    hurtEffect : function(){
        cc.log("hurt effect");
        var rand=GetRandom(0,10);
        if(rand%2==0){
            this.effect0();
        }else{
            this.effect1();
        }
    },
    effect0:function(){
        this.stopAllActions();
        this.runAction( new cc.EaseBounceOut( new cc.Sequence(
            new cc.ScaleTo(0.2,1.2),
            new cc.ScaleTo(0.4,1) )
        ));
    },
    effect1:function(){
        this.stopAllActions();
        this.runAction( new cc.EaseBounceOut( new cc.Sequence(
            new cc.RotateTo(0.2,30), new cc.RotateTo(0.2,0) )
        ));
    },
    collideRect:function (x, y) {
        var width=60,height=50;
        return cc.rect(x-width*0.5, y-height*0.5, width, height);
    }
});
////////////////////////////////////////////////////////////////
GetRole = function () {
    if(g_role){
        cc.log("*** get role down");
        return g_role;
    }else{
        cc.log("*** invalid g_role");
    }
};


